package com.yuma.rag.config;

import com.alibaba.cloud.ai.dashscope.api.DashScopeApi;
import com.alibaba.cloud.ai.dashscope.embedding.DashScopeEmbeddingModel;
import com.alibaba.cloud.ai.dashscope.embedding.DashScopeEmbeddingOptions;
import org.springframework.ai.document.Document;
import org.springframework.ai.document.MetadataMode;
import org.springframework.ai.vectorstore.SimpleVectorStore;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

@Configuration
public class RagConfig {

/*    @Bean  // 生成一个向量库
    public VectorStore vectorStore(OllamaEmbeddingModel ollamaEmbeddingModel){
        //1.创建向量库
        SimpleVectorStore simpleVectorStore = SimpleVectorStore.builder(ollamaEmbeddingModel)
                .build();
        //2.读取要定制的内容（从文件中读取)
        List<Document> documents = List.of(
                new Document("御码电影院" +
                        "票价：\n" +
                        "《731》29.9元\n" +
                        "《志愿军》39.9元\n" +
                        "《刺杀小说家2》34.9元\n" +
                        "《浪浪人生》27.9元\n" +
                        "《风林火山》 68元\n"
                ),
                new Document("退票规则：\n" +
                        "- 价格30元以下扣除10%手续费\n"+
                        "- 价格30元以上扣除15%手续费\n"
                )
        );
        // 3.给向量库喂数据 (自定义知识库)
        simpleVectorStore.add(documents);
        return simpleVectorStore;
    }*/

    @Bean  // 生成一个向量库
    public VectorStore vectorStore(){
        DashScopeEmbeddingModel dashScopeEmbeddingModel = new DashScopeEmbeddingModel(DashScopeApi.builder().apiKey("sk-c2fbaa181da64b7db5c861fc31bfc5be").build(), MetadataMode.EMBED,
                DashScopeEmbeddingOptions.builder().withModel("text-embedding-v4").build());
        //1.创建向量库
        SimpleVectorStore simpleVectorStore = SimpleVectorStore.builder(dashScopeEmbeddingModel)
                .build();
        //2.读取要定制的内容（从文件中读取)
        List<Document> documents = List.of(
                new Document("御码电影院" +
                        "票价：\n" +
                        "-《731》29.9元\n" +
                        "-《志愿军》39.9元\n" +
                        "-《刺杀小说家2》34.9元\n" +
                        "-《浪浪人生》27.9元\n" +
                        "-《风林火山》 68元\n"
                ),
                new Document("退票规则：\n" +
                        "- 价格30元以下扣除10%手续费\n"+
                        "- 价格30元以上扣除15%手续费\n"
                )
        );
        // 3.给向量库喂数据 (自定义知识库)
        simpleVectorStore.add(documents);
        return simpleVectorStore;
    }


}
